#pragma once

#include <boostext/util/make_shared.hpp>
#include <engine.script/Debugger.hpp>
#include <engine.script/Context.hpp>

#include "exports.hpp"
#include "Queue.hpp"




namespace Engine
{
	namespace Debugger
	{
		class ENGINE_DEBUGGER_API Daemon
			: public Script::Debugger
		{
		public:

			SHARED(Daemon);

		protected:
			Daemon(MessageReader::ptr reader, MessageWriter::ptr writer);
			virtual void post_create(ptr _this);

		public:

			MAKE_SHARED2(Daemon, MessageReader::ptr, MessageWriter::ptr);
			virtual ~Daemon();



			/**
			 * @returns the most current pending command, if there is one
			 */
			Command::ptr command();

			/**
			 * Sends the response to a command.
			 */
			template <typename Response>
			void respond(const Response& response)
			{
				m_writer << response;
			}

		protected:

			/**
			 * This function is called after one script-line has been executed.
			 */
			virtual void lineCallback(const Script::Context::ptr& context);

		private:

			MessageReader::ptr    m_reader;
			MessageWriter::ptr   m_writer;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
